<template>
  <div id = "app">

   
    <div class="demo-input-suffix">
        帐号
        <el-input id="p1" v-model="input1" placeholder="请输入帐号"  style="width: 15%" clearable></el-input>
      </div>
      <br/>
      <div class="demo-input-suffix2">
        密码
        <el-input id="p2" v-model="input2" placeholder="请输入密码"  show-password style="width: 15%" clearable></el-input>
      </div>
      <br/>
      <div class="demo-input-suffix3">
        邮箱
        <el-input id="p3" v-model="input3" placeholder="请输入email"   style="width: 15%" clearable></el-input>
      </div>
      
  
      <br/>
      <el-button  @click="doRegister">
        注册
      </el-button>
      <el-button @click="tologin">
        登录
        </el-button>
      
      <router-view/>

  


    <router-view/>
  </div>
  </template>
  
  <script>
  import axios from 'axios'
  export default {
          name: 'register',
          data() {
              return {
                input1: '',
                input2: '',
                input3: ''
                
            }
          },
          methods:{
            doRegister:function(){
              let username=this.input1;
              let password=this.input2;
              let email=this.input3;
              //定义请求路径
              let url='/api/register';
              //定义请求参数
              let params={
                  username:username,
                  password:password,
                  email:email,
                  methodName:'userLogin'
              };
              console.log(params);
              //发起ajax请求GET
              axios.get(url,{params:params}).then(resp=>{
          
                let data=resp.data;
                
                this.$message({
                    message: data.mess,
                    type: data.code==1?'success':'error'
                    
                });
                if (data.code ==1){
                  sessionStorage.setItem('accessToken',data.token)
                  this.$router.push('/');
                }
            
              }).catch(err=>{
                console.log(err);
              });
            },
            tologin:function(){
              this.$router.push('/login');
            }
          }


          



        }
      
    


  </script>